import { ADD_COUNTER, ADD_TOCART } from './mutations-type'

export default {
  [ADD_COUNTER] (state, payload) {
    payload.count++
  },
  [ADD_TOCART] (state, payload) {
    state.cartList.push(payload)
  },
  removeGoodsById (state, id) {
    state.cartList = state.cartList.filter(x => x.id !== id)
    this.commit('saveToStorage')
  },
  saveToStorage (state) {
    localStorage.setItem('cartList', JSON.stringify(state.cartList))
  }
}
